package nineteen;

/**
 * switch语句中的enum
 *
 * @author sun.ye
 * @since 2020-05-01 16:19
 */
public class TrafficLight {
    Signal color = Signal.RED;

    public void change(){
        switch (color){
            case RED:
                color = Signal.GREEN;
                break;
            case GREEN:
                color = Signal.YELLOW;
                break;
            case YELLOW:
                color = Signal.RED;
                break;
            default:
        }
    }

    @Override
    public String toString() {
        return "The traffic light is " + color;
    }

    public static void main(String[] args) {
        TrafficLight t = new TrafficLight();
        for (int i = 0; i < 7 ; i++) {
            System.out.println(t);
            t.change();
        }
    }
}

enum Signal{
    /**
     * 信号颜色
     */
    GREEN,YELLOW,RED
}